// Copyright (c) 2010 Manuel Peinado Gallego <manuel.peinado@gmail.com>
// Distributed under the MIT license

#include "GeometryNode.h"
#include "PrimitiveFactory.h"

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

struct GeometryNodeWrap : public GeometryNode, public bpy::wrapper<GeometryNode>
{
    void setPrimitiveFromType(PrimitiveType type)
    {
        setGeometry(PrimitiveFactory::primitiveFromType(type));
    }

    PrimitiveType getPrimitiveType() const
    {
        const Primitive* prim = dynamic_cast<const Primitive*>(getGeometry().get());
        ASSERT(prim != NULL);
        return PrimitiveFactory::primitiveToType(*prim);
    }
};

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

void pyInitShapeNode()
{
    bpy::class_<GeometryNodeWrap, bpy::bases<TransformNode>, ref<GeometryNodeWrap>,
                boost::noncopyable>("GeometryNode", bpy::init<>())
        .add_property("primitive",
                      &GeometryNodeWrap::getPrimitiveType, 
                      &GeometryNodeWrap::setPrimitiveFromType)
    ;
}
